home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 401-425 / disk_414 / pplib / example.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  99 lines

  1. /*********************************
  2. *                                *
  3. *   powerpacker.library  V34.2   *
  4. *                                *
  5. *   Release 1.1a                 *
  6. *                                *
  7. *   (c) Oct 1990 Nico François   *
  8. *                                *
  9. *   example.c                    *
  10. *                                *
  11. *   This source is public domain *
  12. *   in all respects.             *
  13. *                                *
  14. *********************************/
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <libraries/dos.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21.  
  22. #include <stdio.h>
  23.  
  24. /* if you define NO_PRAGMAS before including proto/powerpacker.h
  25.    you must link with ppSCglue.o or ppLCglue.o */
  26.  
  27. #include <proto/powerpacker.h>
  28. #include <libraries/ppbase.h>
  29.  
  30. struct PPBase *PPBase = NULL;
  31.  
  32. UBYTE *filestart = NULL;
  33. ULONG filelen;
  34.  
  35. char file[108] = "testfile";
  36.  
  37. main()
  38. {
  39.    int err;
  40.  
  41.    if (!(PPBase = (struct PPBase *)OpenLibrary ("powerpacker.library", 0L)))
  42.  
  43.       puts ("You need powerpacker.library V33+ !");
  44.  
  45.    else {
  46.  
  47.       puts ("Loading file...");
  48.  
  49.       err = ppLoadData (file, DECR_POINTER, 0L, &filestart, &filelen, NULL);
  50.       if (err) {
  51.  
  52.           switch (err) {
  53.              case PP_READERR:
  54.                 puts ("Error loading text file !");
  55.                 break;
  56.              case PP_NOMEMORY:
  57.                 puts ("No memory to decrunch file !");
  58.                 break;
  59.              case PP_PASSERR:
  60.                 puts ("Incorrect password, loading aborted !");
  61.                 break;
  62.              case PP_OPENERR:
  63.                 puts ("Can't open file !");
  64.                 break;
  65.              case PP_UNKNOWNPP:
  66.                 puts ("Crunched with unknown PP !");
  67.                 break;
  68.              default:
  69.                 puts ("Unknown error !");
  70.                 break;
  71.              }
  72.  
  73.           }
  74.  
  75.       else {
  76.  
  77.          puts ("file in memory, using it...");
  78.  
  79.          /* file is loaded at 'filestart' and can now be used */
  80.  
  81.          /* ... */
  82.  
  83.          puts ("done, freeing file...");
  84.  
  85.          }
  86.  
  87.       }
  88.  
  89.    /* free all resources */
  90.  
  91.    if (filestart) FreeMem (filestart, filelen);
  92.  
  93.    if (PPBase) CloseLibrary ((struct Library *)PPBase);
  94.  
  95.    puts ("exiting.");
  96.  
  97.    exit (0);
  98. }
  99.